#include "helper/rocksdb/NumberComparator.h"

#include "helper/rocksdb/SliceUtil.h"


namespace helper {
namespace rocksdb {

using SliceUtil = ::helper::rocksdb::SliceUtil;

int NumberComparator::Compare(const ::rocksdb::Slice& a, const ::rocksdb::Slice& b) const {
    if(a.size() == b.size()) {
        if(a.size() >= sizeof(int64_t)){
            return (SliceUtil::toNumber<int64_t>(a) - SliceUtil::toNumber<int64_t>(b));
        }
        else {
            return memcmp(a.data(), b.data(), a.size());
        }
    }
    return (int)a.size() - (int)b.size();
}
const char* NumberComparator::Name() const {
    return "helper.NumberComparator";
}
void NumberComparator::FindShortestSeparator(std::string* start, const ::rocksdb::Slice& limit) const {
}
void NumberComparator::FindShortSuccessor(std::string* key) const {
}
}//end namespace rocksdb
}//end namespace helper
